﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework;
using Engine.Graphics;

namespace Engine
{
    public class GUIUtils
    {

        public static Texture2D whiteTexture = TextureUtils.createBlankTexture(1, 1, Color.White);
        public static Texture2D colorBorder = GraphicsEngine.Instance.Game.Content.Load<Texture2D>("Editor/colorBorder");

        public static Color colorPalette(Color[,] colors, int x, int y, int cellWidth, int cellHeight, Color selected)
        {
            Color returnC = selected;

            for (int i = 0; i < 5; i++)
            {
                for (int j = 0; j < 4; j++)
                {
                    Rectangle destRect = new Rectangle(x + i * (cellWidth + 5), y + j * (cellHeight + 5), cellWidth, cellHeight);
                    Rectangle destRect2 = new Rectangle(x + i * (cellWidth + 5) - 1, y + j * (cellHeight + 5) - 1, cellWidth + 2, cellHeight + 2);
                    GraphicsEngine.Instance.DrawGUITexture(whiteTexture, destRect, null, colors[i, j], Properties.LAYER_GUI_01 - 0.02f);
                    GraphicsEngine.Instance.DrawGUITexture(colorBorder, destRect2, null, Color.White, Properties.LAYER_GUI_01 - 0.03f);

                    if (InputHandler.LeftMouseDown() && new Rectangle((int)InputHandler.MousePosition.X, (int)InputHandler.MousePosition.Y, 1, 1).Intersects(destRect))
                        returnC = colors[i, j];
                }
            }
            return returnC;
        }

        public static void drawToolbarItem(Texture2D tex, int x, int y)
        {
            GraphicsEngine.Instance.DrawGUITexture(tex, new Rectangle(x, y, tex.Width, tex.Height), null, Color.White, Properties.LAYER_GUI_02 - 0.03f);
        }

    }
}
